package com.example.administrator.express.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.express.R;
import com.example.administrator.express.db.UserDao;
import com.example.administrator.express.model.Users;
import com.example.administrator.express.utils.SharedPreferences;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/9/14.
 */
public class MynewsActivity extends Activity {
    @Bind(R.id.loginId)
    TextView loginId;
    @Bind(R.id.phone)
    TextView phone;
    @Bind(R.id.name)
    TextView name;
    @Bind(R.id.adress)
    TextView adress;
    @Bind(R.id.btnBack)
    Button btnBack;
    @Bind(R.id.loginout)
    Button loginout;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_news);
        ButterKnife.bind(this);
        initdate();
    }

    private void initdate() {
        SharedPreferences sharedPreferences = SharedPreferences.getInstance();
        Integer login = sharedPreferences.getInt("loginId", 0);
        UserDao userdao = new UserDao(getApplicationContext());
        Users users = userdao.getByLoginId(login);
        loginId.setText(String.valueOf(users.getLoginId()));
        phone.setText(String.valueOf(users.getPhone()));
        name.setText(users.getName());
        adress.setText(users.getAdress());
    }


    @OnClick({R.id.btnBack, R.id.loginout})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnBack:
                this.finish();
                break;
            case R.id.loginout:
                SharedPreferences sharedPreferences = SharedPreferences.getInstance();
               Integer loginId= sharedPreferences.getInt("loginId",0);
                sharedPreferences.remove("loginId");
                System.out.println("已shanchucunchu：" );
                UserDao userdao = new UserDao(getApplicationContext());
                Users localusers = userdao.getByLoginId(loginId);
                userdao.delete(localusers);
                System.out.println("已shanchu数据库：" );
                Intent intent1 = new Intent(this, Appstart.class);
                startActivity(intent1);
                 finish();
                break;
        }
    }
}
